package com.ruoyi.active.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.active.domain.TbActive;
import com.ruoyi.active.service.ITbActiveService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 抽奖活动管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-01
 */
@RestController
@RequestMapping("/active")
public class TbActiveController extends BaseController
{
    @Autowired
    private ITbActiveService tbActiveService;

    /**
     * 查询抽奖活动管理列表
     */
    @RequiresPermissions("active:active:list")
    @GetMapping("/list")
    public TableDataInfo list(TbActive tbActive)
    {
        startPage();
        List<TbActive> list = tbActiveService.selectTbActiveList(tbActive);
        return getDataTable(list);
    }

    /**
     * 导出抽奖活动管理列表
     */
    @RequiresPermissions("active:active:export")
    @Log(title = "抽奖活动管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbActive tbActive)
    {
        List<TbActive> list = tbActiveService.selectTbActiveList(tbActive);
        ExcelUtil<TbActive> util = new ExcelUtil<TbActive>(TbActive.class);
        util.exportExcel(response, list, "抽奖活动管理数据");
    }

    /**
     * 获取抽奖活动管理详细信息
     */
    @RequiresPermissions("active:active:query")
    @GetMapping(value = "/{activeId}")
    public AjaxResult getInfo(@PathVariable("activeId") Integer activeId)
    {
        return success(tbActiveService.selectTbActiveByActiveId(activeId));
    }

    /**
     * 新增抽奖活动管理
     */
    @RequiresPermissions("active:active:add")
    @Log(title = "抽奖活动管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbActive tbActive)
    {
        return toAjax(tbActiveService.insertTbActive(tbActive));
    }

    /**
     * 修改抽奖活动管理
     */
    @RequiresPermissions("active:active:edit")
    @Log(title = "抽奖活动管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbActive tbActive)
    {
        return toAjax(tbActiveService.updateTbActive(tbActive));
    }

    /**
     * 删除抽奖活动管理
     */
    @RequiresPermissions("active:active:remove")
    @Log(title = "抽奖活动管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activeIds}")
    public AjaxResult remove(@PathVariable Integer[] activeIds)
    {
        return toAjax(tbActiveService.deleteTbActiveByActiveIds(activeIds));
    }
}
